package com.dcm.live.controller;

import com.dcm.common.annotation.EnableResponseBodyAdvice;
import com.dcm.live.entity.LiveItemEntity;
import com.dcm.live.service.LiveBuyService;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author 牛浩
 */
@Api(tags = "LiveBuyController")
@RestController
@EnableResponseBodyAdvice
@RequestMapping("/LiveBuy")
public class LiveBuyController {
    @Autowired
    private LiveBuyService liveBuyService;

    @ApiOperation("根据id查询")
    @GetMapping("/findById")
    public LiveItemEntity findById(@RequestParam(value = "id",required = false) Long id){
        return liveBuyService.findById(id);
    }

    @ApiOperation("查询所有直播商品")
    @GetMapping("/findAll")
    public List<LiveItemEntity> findAll(){
        return liveBuyService.findAll();
    }

    @ApiOperation("加入购物车")
    @PostMapping("/shopCar")
    public void shopCar(@RequestParam(value = "id",required = false) Long id,
                        @RequestParam(value = "uid",required = false) Long uid){
        liveBuyService.shopCar(id,uid);
    }

    @ApiOperation("购买")
    @GetMapping("shopBuy")
    public void shopBuy(@RequestParam(value = "uid", required = false) Long uid) {
        liveBuyService.shopBuy(uid);
    }


    @ApiOperation("发表弹幕")
    @GetMapping("releaseBarrage")
    public void releaseBarrage(@RequestParam(value = "barrage", required = false) String barrage,
                               @RequestParam(value = "uid", required = false) Long uid) {
        liveBuyService.releaseBarrage(barrage, uid);
    }
    @ApiOperation("分页")
    @GetMapping("/findPage")
    public PageInfo<LiveItemEntity> findPage(@RequestParam(value = "currentPage", required = false) Integer currentPage,
                                             @RequestParam(value = "pageSize", required = false) Integer pageSize) {
        return liveBuyService.findPage(currentPage, pageSize);
    }
}